 package Cliente;


import Conexion.SerializedObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.net.Socket;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.net.UnknownHostException;

/**
 *
 * @author usuario
 */
public class Cliente {

        private ObjectOutputStream oos = null;
        private ObjectInputStream ois = null;
        private Socket socket=null;

        /**
         *
         * @param Ip
         * @param Port
         */
        public void crerConex(String Ip,int Port){
            try{
                socket = new Socket(Ip,Port);// open I/O streams for objects
                oos = new ObjectOutputStream(socket.getOutputStream());
                ois = new ObjectInputStream(socket.getInputStream());
            }catch(Exception e){
                e.printStackTrace();
            }
        }

        /**
         *
         * @param so
         */
        public void enviar(SerializedObject so){
            try{
                // write the objects to the server
                oos.writeObject(so);
                oos.flush();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
        /**
         *
         * @return
         */
        public SerializedObject recibir(){
                SerializedObject result = null;
            try{
                // read an object from the server
                result = (SerializedObject) ois.readObject();
            }catch(Exception e){
                e.printStackTrace();
            }
            return result;
        }

        /**
         *
         */
        public void close(){
           try {
                oos.close();
                ois.close();
                socket.close();
           }catch(Exception e){
                System.out.println(e.getMessage());
           }
        }
}